package com.fc.mall.portal.orika;

import com.fc.mall.model.UmsMemberSign;
import com.fc.mall.orika.MapperConfigurer;
import com.fc.mall.portal.dto.MemberSignDto;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.MappingContext;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MemberSignMapperConfigurer implements MapperConfigurer {
    @Override
    public void configure(MapperFactory mapperFactory) {
        mapperFactory.classMap(UmsMemberSign.class, MemberSignDto.class)
                .customize(new CustomMapper<UmsMemberSign, MemberSignDto>() {
                    @Override
                    public void mapAtoB(UmsMemberSign memberSign, MemberSignDto memberSignDto, MappingContext context) {
                        if (memberSign.getLastModifyTime() != null &&
                                DateUtils.isSameDay(memberSign.getLastModifyTime(), new Date()))
                            memberSignDto.setSignedToday(true);
                    }
                })
                .byDefault()
                .register();
    }
}
